<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是天猫精灵IOT Smart config—— 多播配网代码分析相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析">
<meta property="og:url" content="https://sumumm.github.io/post/23891e91.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是天猫精灵IOT Smart config—— 多播配网代码分析相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/1.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/image-20231222202846088.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/image-20231220204929482.png">
<meta property="article:published_time" content="2023-12-22T14:28:32.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.026Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV21-天猫精灵IOT">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/1.png">


<link rel="canonical" href="https://sumumm.github.io/post/23891e91.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/23891e91.html","path":"post/23891e91.html","title":"LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%9C%A8%E5%93%AA%EF%BC%9F"><span class="nav-text">一、多播配网代码在哪？</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%A4%9A%E6%92%AD%E6%8A%A5%E6%96%87%E8%A7%A3%E6%9E%90"><span class="nav-text">二、多播报文解析</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%A4%9A%E6%92%AD%E6%8A%A5%E6%96%87%E5%9C%A8%E5%93%AA%E8%A7%A3%E6%9E%90%EF%BC%9F"><span class="nav-text">1. 多播报文在哪解析？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8%E5%85%B3%E7%B3%BB"><span class="nav-text">1.1 函数调用关系</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-ieee80211-data-extract-%E5%87%BD%E6%95%B0"><span class="nav-text">1.1 ieee80211_data_extract()函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-awss-protocol-couple-array-%E6%95%B0%E7%BB%84"><span class="nav-text">1.2 awss_protocol_couple_array[]数组</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-awss-ieee80211-mcast-smartconfig-process-%E5%87%BD%E6%95%B0"><span class="nav-text">2. awss_ieee80211_mcast_smartconfig_process()函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-awss-recv-callback-mcast-smartconfig-%E5%87%BD%E6%95%B0"><span class="nav-text">3. awss_recv_callback_mcast_smartconfig()函数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%BA%8F%E5%88%97%E5%8F%B7sn"><span class="nav-text">3.1 序列号sn</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%87%BD%E6%95%B0%E8%A7%A3%E6%9E%90"><span class="nav-text">3.2 函数解析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-parse-result"><span class="nav-text">3.3 parse_result()</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E5%AF%86%E7%A0%81%E8%A7%A3%E6%9E%90"><span class="nav-text">3.4 密码解析</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/23891e91.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-12-22 22:28:32" itemprop="dateCreated datePublished" datetime="2023-12-22T22:28:32+08:00">2023-12-22</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/" itemprop="url" rel="index"><span itemprop="name">LV21-天猫精灵IOT</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.8k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>14 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是天猫精灵IOT Smart config—— 多播配网代码分析相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu22.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="6">官方网站</td>        <td align="left"><a href="https://cn.aliyun.com/" target="_blank">阿里云</a></td>        <td align="left">阿里云官网主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.aliyun.com/product/iot/livinglink?spm=5176.28508143.J_4VYgf18xNlTAyFFbOuOQe.317.5421154acZniIL&scm=20140722.X_data-1da961ea118f5bb0e4b2._.V_1" target="_blank">阿里生活物联平台</a></td>        <td align="left">生活物联网平台(飞燕平台)主页</td>    </tr>    <tr>        <td align="left"><a href="https://iap.aligenie.com/?spm=0.7629140.0.0.2c611780Ty6tzg" target="_blank">AliGenie</a></td>        <td align="left">天猫精灵开放平台AliGenie主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.aliyun.com/product/iot/iot_instc_public_cn?spm=5176.28508143.J_4VYgf18xNlTAyFFbOuOQe.81.5421154au3ocqp&scm=20140722.X_data-9349178ba84cf028806a._.V_1" target="_blank">阿里物联网平台</a></td>        <td align="left">阿里物联网平台主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/" target="_blank">Bluetooth 技术网站</a></td>        <td align="left">蓝牙协议规范什么的可以来这里找</td>    </tr>    <tr>        <td align="left"><a href="https://www.telink-semi.com/" target="_blank">Telink</a></td>        <td align="left">Telink | Chips for a Smarter IoT (telink-semi.com)<br><a href="https://www.telink-semi.cn/" target="_blank">Telink中文官网</a></td>    </tr>    <tr>        <td align="center" rowspan="5">开发手册</td>        <td align="left"><a href="https://help.aliyun.com/zh/alios-things/" target="_blank">AliOS Things开发指南</a></td>        <td align="left">AliOS Things开发指南，这里是最新版本，可以直接从官网找到</td>    </tr>     <tr>        <td align="left"><a href="https://haas.iot.aliyun.com/aliosthings/index.html" target="_blank">AliOS Things开发指南</a></td>        <td align="left">AliOS Things应用开发指南，这里应该是3.3版本的完整开发文档</td>    </tr>    <tr>        <td align="left"><a href="https://gaic.alicdn.com/aic/h5_daily/test/aliosthings/3.0.13/index.html" target="_blank">AliOS Things开发指南(3.0)</a></td>        <td align="left">AliOS Things应用开发指南，这里应该是3.0版本的完整开发文档</td>    </tr>    <tr>        <td align="left"><a href="https://help.aliyun.com/product/123207.html?spm=a2c4g.11186623.6.540.114e60d84sF58G" target="_blank">生活物联网平台开发文档</a></td>        <td align="left">生活物联网平台（飞燕平台）开发文档<br><a href="https://help.aliyun.com/document_detail/180778.html?spm=a2c4g.123207.0.0.49556adcO5apvd" target="_blank">《设备端开发指南》</a></td>    </tr>    <tr>        <td align="left"><a href="https://doc-bot.tmall.com/docs/doc.htm?spm=0.7629140.0.0.7bf81780UN7WkQ&treeId=578&articleId=118057&docType=1" target="_blank">Wi-Fi IoT品类定义与功能开发</a></td>        <td align="left">天猫精灵IoT开放平台——Wi-Fi IoT品类定义与功能开发</td>    </tr>    <tr>        <td align="center" rowspan="3">硬件平台</td>        <td align="left"><a href="https://developer.aliyun.com/article/761644?spm=a2c6h.12873581.0.dArticle761644.1c1b589dRHgvcR&groupCode=genieaiot" target="_blank">mk3080 WiFi开发板</a></td>        <td align="left">WiFi开发板使用指南-阿里云开发者社区</td>    </tr>    <tr>        <td align="left"><a href="http://www.taichi-maker.com/homepage/esp8266-nodemcu-iot/esp8266-nodemcu-tutorial-index/" target="_blank">esp8266开发板</a></td>        <td align="left">一个教程：ESP8266-NodeMCU开发板详解-太极创客 (taichi-maker.com)</td>    </tr>    <tr>        <td align="left"><a href="https://wiki.telink-semi.cn/doc/ds/DS_TLSR8258-E_Datasheet%20for%20Telink%20BLE+IEEE802.15.4%20Multi-Standard%20Wireless%20SoC%20TLSR8258.pdf" target="_blank">TLSR8258 Datasheet</a></td>        <td align="left">Datasheet for Telink BLE + IEEE802.15.4 MultiStandard Wireless SoC TLSR8258</td>    </tr>    <tr>        <td align="center" rowspan="2">参考资料</td>        <td align="left"><a href="https://developer.aliyun.com/article/720516#" target="_blank">AliOS Things 3.0 应用开发指南</a></td>        <td align="left">这个只是一篇参考文章，里面是一些环境搭建相关的，可以参考</td>    </tr>    <tr>        <td align="left"><a href="https://info.support.huawei.com/info-finder/encyclopedia/zh/index.html" target="_blank">IP知识百科 - 华为 (huawei.com)</a></td>        <td align="left">IP的一些相关知识点</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="left" rowspan="6">蓝牙规范相关文档</td>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/core-specification-5-2/" target="_blank">Core Specification 5.2</a></td>        <td align="left">核心规格 5.2，该规范定义了创建可互操作的Bluetooth 设备所需的技术。                        <br><a href="./蓝牙参考资料/Core_v5.2.pdf" target="_blank">《Core_v5.2.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/mesh-model-1-1/" target="_blank">Mesh Model(v1.1)</a></td>        <td align="left">本Bluetooth 规范定义了模型（以及它们所需的状态和消息），这些模型用于在mesh 网络中的节点上执行基本功能，超出了Bluetooth Mesh 配置文件 规范中定义的基础模型。                        <br>本规范包括定义跨设备类型标准功能的通用模型，以及支持关键mesh 场景的模型，如照明控制、传感器、时间和场景。                        <br><a href="./蓝牙参考资料/MshMDL_v1.1.pdf" target="_blank">《MshMDL_v1.1.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/mesh-profile-1-0-1/" target="_blank">Mesh Profile(v1.0.1)</a></td>        <td align="left">该Bluetooth 规范定义了基本要求，以实现可互操作的mesh 网络解决方案，用于Bluetooth 低能量无线技术。                        <br><a href="./蓝牙参考资料/MshPRFv1.0.1.pdf" target="_blank">《MshPRFv1.0.1.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/device-properties/" target="_blank">Mesh Device Properties</a></td>        <td align="left">本规范包含Bluetooth Mesh 配置文件 和Bluetooth Mesh 模型规范所要求的设备属性的定义。                        <br>但是跟之前的有些区别，我主要看的之前的版本：<a href="./蓝牙参考资料/MeshDeviceProperties_v1.2.pdf" target="_blank">《MMeshDeviceProperties_v1.2.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/specifications/gss/" target="_blank">GATT Specification Supplement</a></td>        <td align="left">GATT Specification Supplement | Bluetooth® Technology Website。                        <br>好像可以在线看：<a href="https://btprodspecificationrefs.blob.core.windows.net/gatt-specification-supplement/GATT_Specification_Supplement.pdf" target="_blank">《GATT Specification Supplement》</a></td>      </tr>     <tr>        <td align="left"><a href="https://www.bluetooth.com/specifications/assigned-numbers/" target="_blank">Assigned Numbers</a></td>        <td align="left">GATT的一些类型定义可以在这里找。</td>      </tr>    <tr>        <td align="left" rowspan="2">AliOS Things</td>        <td align="left"><a href="https://gitee.com/alios-things-admin/AliOS-Things" target="_blank">alios-things/AliOS-Things</a></td>        <td align="left">Gitee上的AliOSThings SDK源码仓库</td>      </tr>    <tr>        <td align="left"><a href="https://github.com/alibaba/AliOS-Things" target="_blank">alibaba/AliOS-Things</a></td>        <td align="left">GitHub上的AliOSThings SDK源码仓库</td>      </tr>    <tr>        <td align="left" rowspan="2">天猫精灵蓝牙Mesh协议栈</td>        <td align="left"><a href="https://github.com/alibaba-archive/genie-bt-mesh-stack" target="_blank">alibaba-archive/genie-bt-mesh-stack</a></td>        <td align="left">GitHub上的天猫精灵蓝牙Mesh协议栈源码仓库。<br>之前是在<a href="https://github.com/alibaba/genie-bt-mesh-stack"target="_blank">alibaba/genie-bt-mesh-stack</a>这个仓库。<br>写笔记的时候最新提交为<a href="https://github.com/alibaba-archive/genie-bt-mesh-stack/tree/faf523618a6a2560090fc423222b9db80984bb7a" target="_blank">faf523618a6a2560090fc423222b9db80984bb7a</a></td>      </tr>    <tr>        <td align="left"><a href="https://help.aliyun.com/document_detail/171552.html?spm=a2c4g.173310.0.0.55d6e992e8xJip" target="_blank">蓝牙Mesh设备开发指南</a></td>        <td align="left">阿里云生活服务平台开发手册——蓝牙设备开发一节中的内容</td>      </tr></table>
              </div>
            </details>

<h1 id="一、多播配网代码在哪？"><a href="#一、多播配网代码在哪？" class="headerlink" title="一、多播配网代码在哪？"></a><font size=3>一、多播配网代码在哪？</font></h1><p>多播配网的相关代码在这里：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">hk@vm:~/AliOS-Things-SDK/components/linkkit/wifi_provision$ tree -L 2</span><br><span class="line">.</span><br><span class="line">├── # ......</span><br><span class="line">├── frameworks</span><br><span class="line">├── # ......</span><br><span class="line">├── mcast_smartconfig</span><br><span class="line">│   └── mcast_smartconfig.c</span><br><span class="line"></span><br><span class="line">15 directories, 55 files</span><br></pre></td></tr></table></figure>

<p>为什么文件这么少？其实它有大部分的代码和零配是一样的，比如配网开始、配网初始化等，有一部分都是共用的，其实主要区别是在处理报文的过程，其他的大部分过程都是一样的。</p>
<h1 id="二、多播报文解析"><a href="#二、多播报文解析" class="headerlink" title="二、多播报文解析"></a><font size=3>二、多播报文解析</font></h1><h2 id="1-多播报文在哪解析？"><a href="#1-多播报文在哪解析？" class="headerlink" title="1. 多播报文在哪解析？"></a><font size=3>1. 多播报文在哪解析？</font></h2><h3 id="1-1-函数调用关系"><a href="#1-1-函数调用关系" class="headerlink" title="1.1 函数调用关系"></a><font size=3>1.1 函数调用关系</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/1.png" alt="1" />

<h3 id="1-1-ieee80211-data-extract-函数"><a href="#1-1-ieee80211-data-extract-函数" class="headerlink" title="1.1 ieee80211_data_extract()函数"></a><font size=3>1.1 ieee80211_data_extract()函数</font></h3><p>我们看这个ieee80211_data_extract()函数，其实前面有提到过：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * ieee80211_data_extratct - extract 80211 frame info</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @in: [IN] 80211 frame</span></span><br><span class="line"><span class="comment"> * @len: [IN] 80211 frame len</span></span><br><span class="line"><span class="comment"> * @link_type: [IN] link type @see enum AWS_LINK_TYPE</span></span><br><span class="line"><span class="comment"> * @res: [OUT] 80211 frame parser result, see struct parser_res.</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @warning: encry_type may collision with aes &amp; tpip in some cases,</span></span><br><span class="line"><span class="comment"> *         then encry_type will be set to INVALID.</span></span><br><span class="line"><span class="comment"> * @Return:</span></span><br><span class="line"><span class="comment"> *     @see enum ALINK_TYPE</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @Note: howto deal with radio RSSI signal</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">ieee80211_data_extract</span><span class="params">(<span class="type">uint8_t</span> *in, <span class="type">int</span> len, <span class="type">int</span> link_type, <span class="keyword">struct</span> parser_res *res, <span class="type">signed</span> <span class="type">char</span> rssi)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">ieee80211_hdr</span> *<span class="title">hdr</span>;</span></span><br><span class="line">    <span class="type">int</span> alink_type = ALINK_INVALID;</span><br><span class="line">    <span class="type">int</span> pkt_type = PKG_INVALID;</span><br><span class="line">    <span class="type">int</span> i, fc;</span><br><span class="line"></span><br><span class="line">    hdr = (<span class="keyword">struct</span> ieee80211_hdr *)zconfig_remove_link_header(&amp;in, &amp;len, link_type);</span><br><span class="line">    <span class="keyword">if</span> (len &lt;= <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">goto</span> drop;</span><br><span class="line">    fc = hdr-&gt;frame_control;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; <span class="keyword">sizeof</span>(awss_protocol_couple_array) / <span class="keyword">sizeof</span>(awss_protocol_couple_array[<span class="number">0</span>]); i ++) &#123;</span><br><span class="line">        awss_protocol_process_func_type protocol_func = awss_protocol_couple_array[i].awss_protocol_process_func;</span><br><span class="line">        <span class="keyword">if</span> (protocol_func == <span class="literal">NULL</span>)</span><br><span class="line">            <span class="keyword">continue</span>;</span><br><span class="line">        alink_type = protocol_func((<span class="type">uint8_t</span> *)hdr, len, link_type, res, rssi);</span><br><span class="line">        <span class="keyword">if</span> (alink_type != ALINK_INVALID)</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (alink_type == ALINK_INVALID)</span><br><span class="line">        <span class="keyword">goto</span> drop;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (alink_type != ALINK_HT_CTRL) &#123;</span><br><span class="line">        <span class="comment">/* convert IEEE 802.11 header + possible LLC headers into Ethernet header</span></span><br><span class="line"><span class="comment">         * IEEE 802.11 address fields:</span></span><br><span class="line"><span class="comment">         * ToDS FromDS Addr1 Addr2 Addr3 Addr4</span></span><br><span class="line"><span class="comment">         *   0     0   DA    SA    BSSID n/a</span></span><br><span class="line"><span class="comment">         *   0     1   DA    BSSID SA    n/a</span></span><br><span class="line"><span class="comment">         *   1     0   BSSID SA    DA    n/a</span></span><br><span class="line"><span class="comment">         *   1     1   RA    TA    DA    SA</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        res-&gt;src = ieee80211_get_SA(hdr);</span><br><span class="line">        res-&gt;dst = ieee80211_get_DA(hdr);</span><br><span class="line">        res-&gt;bssid = ieee80211_get_BSSID(hdr);</span><br><span class="line">        res-&gt;tods = ieee80211_has_tods(fc);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">do</span> &#123;</span><br><span class="line">        awss_protocol_finish_func_type finish_func = awss_protocol_couple_array[i].awss_protocol_finish_func;</span><br><span class="line">        <span class="keyword">if</span> (finish_func)</span><br><span class="line">            pkt_type = finish_func(res);</span><br><span class="line">    &#125; <span class="keyword">while</span>(<span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">drop:</span><br><span class="line">    <span class="keyword">return</span> pkt_type;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以看到这里主要是调用了两个函数指针指向的函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">awss_protocol_couple_array[i].awss_protocol_process_func</span><br><span class="line">awss_protocol_couple_array[i].awss_protocol_finish_func</span><br></pre></td></tr></table></figure>

<h3 id="1-2-awss-protocol-couple-array-数组"><a href="#1-2-awss-protocol-couple-array-数组" class="headerlink" title="1.2 awss_protocol_couple_array[]数组"></a><font size=3>1.2 awss_protocol_couple_array[]数组</font></h3><p>这个数组定义在：AOS_SDK_PATH&#x2F;components&#x2F;linkkit&#x2F;wifi_provision&#x2F;frameworks&#x2F;ieee80211&#x2F;zconfig_ieee80211.c中：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">awss_protocol_couple_type</span> <span class="title">awss_protocol_couple_array</span>[] =</span> &#123;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_HT40</span></span><br><span class="line">    &#123;ALINK_HT_CTRL,      awss_ieee80211_ht_ctrl_process,     awss_recv_callback_ht_ctrl&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_APLIST</span></span><br><span class="line">    &#123;ALINK_APLIST,       awss_ieee80211_aplist_process,      <span class="literal">NULL</span>&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_AHA</span></span><br><span class="line">    &#123;ALINK_DEFAULT_SSID, awss_ieee80211_aha_process,         awss_recv_callback_aha_ssid&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifndef</span> AWSS_DISABLE_ENROLLEE</span></span><br><span class="line">    &#123;ALINK_ZERO_CONFIG,  awss_ieee80211_zconfig_process,     awss_recv_callback_zconfig&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_SMARTCONFIG_WPS</span></span><br><span class="line">    &#123;ALINK_WPS,          awss_ieee80211_wps_process,         awss_recv_callback_wps&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_SMARTCONFIG</span></span><br><span class="line">    &#123;ALINK_BROADCAST,    awss_ieee80211_smartconfig_process, awss_recv_callback_smartconfig&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_SMARTCONFIG_MCAST</span></span><br><span class="line">    &#123;ALINK_BROADCAST,    awss_ieee80211_mcast_smartconfig_process, awss_recv_callback_mcast_smartconfig&#125;,</span><br><span class="line"> <span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_DISCOVER</span></span><br><span class="line">    &#123;ALINK_BROADCAST,       aws_discover_callback,      <span class="literal">NULL</span>&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>我们这里分析广播配网的代码，所以这里主要是看这两个函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_SMARTCONFIG</span></span><br><span class="line">    &#123;ALINK_BROADCAST,    awss_ieee80211_smartconfig_process, awss_recv_callback_smartconfig&#125;,</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<h2 id="2-awss-ieee80211-mcast-smartconfig-process-函数"><a href="#2-awss-ieee80211-mcast-smartconfig-process-函数" class="headerlink" title="2. awss_ieee80211_mcast_smartconfig_process()函数"></a><font size=3>2. awss_ieee80211_mcast_smartconfig_process()函数</font></h2><p>awss_ieee80211_mcast_smartconfig_process() 函数定义在AOS_SDK_PATH&#x2F;components&#x2F;linkkit&#x2F;wifi_provision&#x2F;mcast_smartconfig&#x2F;mcast_smartconfig.c中：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">awss_ieee80211_mcast_smartconfig_process</span><span class="params">(<span class="type">uint8_t</span> *ieee80211, <span class="type">int</span> len, <span class="type">int</span> link_type, <span class="keyword">struct</span> parser_res *res,</span></span><br><span class="line"><span class="params">        <span class="type">signed</span> <span class="type">char</span> rssi)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> hdrlen, fc, seq_ctrl;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">ieee80211_hdr</span> *<span class="title">hdr</span>;</span></span><br><span class="line">    <span class="type">uint8_t</span> *data, *bssid_mac, *dst_mac;</span><br><span class="line">    <span class="type">uint8_t</span> encry = ZC_ENC_TYPE_INVALID;</span><br><span class="line">    <span class="type">uint8_t</span> tods;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * when device try to connect current router (include aha)</span></span><br><span class="line"><span class="comment">     * skip the new packet.</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">if</span> (ieee80211 == <span class="literal">NULL</span> || zconfig_finished) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * we don&#x27;t process smartconfig until user press configure button</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">if</span> (awss_get_config_press() == <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    hdr = (<span class="keyword">struct</span> ieee80211_hdr *)ieee80211;</span><br><span class="line">    fc = hdr-&gt;frame_control;</span><br><span class="line">    seq_ctrl = hdr-&gt;seq_ctrl;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * for smartconfig with bcast of data</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">if</span> (!ieee80211_is_data_exact(fc)) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* tods = 1, fromds = 0 || tods = 0, fromds = 1 */</span></span><br><span class="line">    <span class="keyword">if</span> (ieee80211_has_tods(fc) == ieee80211_has_fromds(fc)) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* drop frag, more, order*/</span></span><br><span class="line">    <span class="keyword">if</span> (ieee80211_has_frags(fc)) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    dst_mac = (<span class="type">uint8_t</span> *)ieee80211_get_DA(hdr);</span><br><span class="line">    <span class="comment">/* only multicast is passed */</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0x1</span> != dst_mac[<span class="number">0</span>] || <span class="number">0x0</span> != dst_mac[<span class="number">1</span>] || <span class="number">0x5e</span> != dst_mac[<span class="number">2</span>]) &#123;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> VERBOSE_MCAST_DEBUG</span></span><br><span class="line">        awss_debug(<span class="string">&quot;error type, %x, %x, %x\n&quot;</span>, dst_mac[<span class="number">0</span>], dst_mac[<span class="number">1</span>], dst_mac[<span class="number">2</span>]);</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;    <span class="comment">/* only handle br frame */</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    bssid_mac = (<span class="type">uint8_t</span> *)ieee80211_get_BSSID(hdr);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">     * payload len = frame.len - (radio_header + wlan_hdr)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    hdrlen = ieee80211_hdrlen(fc);</span><br><span class="line">    <span class="keyword">if</span> (hdrlen &gt; len) &#123;</span><br><span class="line">        <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> _PLATFORM_QCOM_</span></span><br><span class="line">    <span class="comment">/* Note: http://stackoverflow.com/questions/17688710/802-11-qos-data-frames */</span></span><br><span class="line">    hdrlen = (hdrlen + <span class="number">3</span>) &amp; <span class="number">0xFC</span>;<span class="comment">/* align header to 32bit boundary */</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"></span><br><span class="line">    res-&gt;u.br.data_len = len - hdrlen;       <span class="comment">/* eating the hdr */</span></span><br><span class="line">    res-&gt;u.br.sn = IEEE80211_SEQ_TO_SN(os_le16toh(seq_ctrl));</span><br><span class="line"></span><br><span class="line">    data = ieee80211 + hdrlen;               <span class="comment">/* eating the hdr */</span></span><br><span class="line">    tods = ieee80211_has_tods(fc);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">do</span> &#123;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> AWSS_SUPPORT_APLIST</span></span><br><span class="line">        <span class="class"><span class="keyword">struct</span> <span class="title">ap_info</span> *<span class="title">ap_info</span>;</span></span><br><span class="line">        ap_info = zconfig_get_apinfo(bssid_mac);</span><br><span class="line">        <span class="keyword">if</span> (ap_info &amp;&amp; ZC_ENC_TYPE_INVALID != ap_info-&gt;encry[tods]) &#123;</span><br><span class="line">            encry = ap_info-&gt;encry[tods];</span><br><span class="line">        &#125; <span class="keyword">else</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (!ieee80211_has_protected(fc)) &#123;</span><br><span class="line">                encry = ZC_ENC_TYPE_NONE;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">/* Note: avoid empty null data */</span></span><br><span class="line">                <span class="keyword">if</span> (len &lt; <span class="number">8</span>) &#123;      <span class="comment">/* IV + ICV + DATA &gt;= 8 */</span></span><br><span class="line">                    <span class="keyword">return</span> ALINK_INVALID;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (!(ieee80211[<span class="number">3</span>] &amp; <span class="number">0x3F</span>)) &#123;</span><br><span class="line">                    encry = ZC_ENC_TYPE_WEP;</span><br><span class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (data[<span class="number">3</span>] &amp; (<span class="number">1</span> &lt;&lt; <span class="number">5</span>)) &#123;<span class="comment">/* Extended IV */</span></span><br><span class="line">                    <span class="keyword">if</span> (data[<span class="number">1</span>] == ((data[<span class="number">0</span>] | <span class="number">0x20</span>) &amp; <span class="number">0x7F</span>)) &#123; <span class="comment">/* tkip, WEPSeed  = (TSC1 | 0x20 ) &amp; 0x7F */</span></span><br><span class="line">                        encry = ZC_ENC_TYPE_TKIP;</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">if</span> (data[<span class="number">2</span>] == <span class="number">0</span> &amp;&amp; (!(data[<span class="number">3</span>] &amp; <span class="number">0x0F</span>))) &#123;</span><br><span class="line">                        encry = ZC_ENC_TYPE_AES;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="comment">/*</span></span><br><span class="line"><span class="comment">                     * Note: above code use if(tkip) and if(ase)</span></span><br><span class="line"><span class="comment">                     * instead of if(tkip) else if(aes)</span></span><br><span class="line"><span class="comment">                     * beacause two condition may bother match.</span></span><br><span class="line"><span class="comment">                     */</span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">while</span> (<span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (encry == ZC_ENC_TYPE_INVALID) &#123;</span><br><span class="line">        awss_warn(<span class="string">&quot;invalid encry type!\r\n&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    res-&gt;u.br.encry_type = encry;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* convert IEEE 802.11 header + possible LLC headers into Ethernet header</span></span><br><span class="line"><span class="comment">     * IEEE 802.11 address fields:</span></span><br><span class="line"><span class="comment">     * ToDS FromDS Addr1 Addr2 Addr3 Addr4</span></span><br><span class="line"><span class="comment">     *   0     0   DA    SA    BSSID n/a</span></span><br><span class="line"><span class="comment">     *   0     1   DA    BSSID SA    n/a</span></span><br><span class="line"><span class="comment">     *   1     0   BSSID SA    DA    n/a</span></span><br><span class="line"><span class="comment">     *   1     1   RA    TA    DA    SA</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    res-&gt;src = ieee80211_get_SA(hdr);</span><br><span class="line">    res-&gt;dst = ieee80211_get_DA(hdr);</span><br><span class="line">    res-&gt;bssid = ieee80211_get_BSSID(hdr);</span><br><span class="line">    res-&gt;tods = ieee80211_has_tods(fc);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> ALINK_BROADCAST;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>可以看出，这个函数主要是对基本信息进行解析，并且判断是否是smart config多播报文。</p>
<h2 id="3-awss-recv-callback-mcast-smartconfig-函数"><a href="#3-awss-recv-callback-mcast-smartconfig-函数" class="headerlink" title="3. awss_recv_callback_mcast_smartconfig()函数"></a><font size=3>3. awss_recv_callback_mcast_smartconfig()函数</font></h2><h3 id="3-1-序列号sn"><a href="#3-1-序列号sn" class="headerlink" title="3.1 序列号sn"></a><font size=3>3.1 序列号sn</font></h3><p>下面会有一个sn的概念，他是干嘛用的？我们看一下抓到的包：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/image-20231222202846088.png" alt="image-20231222202846088" />

<p><code>seq（Sequence Number）</code>：<code>32bits</code>，表示这个数据包的序列号，每个帧的seq都是不一样的。可以根据<code>seq</code>来确定顺序，并且能够确定是否有数据包丢失。我们在配网的时候，UDP广播报文是很可能会产生丢帧的，接收到的顺序可能不是发送的顺序，这个seq可以帮助设备分辨收到的帧是否是连续的。比如丢的，重复的，都可以被标记出来进行对应的处理。</p>
<h3 id="3-2-函数解析"><a href="#3-2-函数解析" class="headerlink" title="3.2 函数解析"></a><font size=3>3.2 函数解析</font></h3><p>awss_recv_callback_mcast_smartconfig()函数定义在AOS_SDK_PATH&#x2F;components&#x2F;linkkit&#x2F;wifi_provision&#x2F;mcast_smartconfig&#x2F;mcast_smartconfig.c中，这里摆一张有效数据的图片：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV02-01-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT-07-SmartConfig-05-%E5%A4%9A%E6%92%AD%E9%85%8D%E7%BD%91%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90/img/image-20231220204929482.png" alt="image-20231220204929482" />

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">awss_recv_callback_mcast_smartconfig</span><span class="params">(<span class="keyword">struct</span> parser_res *res)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint8_t</span> index = *(res-&gt;dst + <span class="number">3</span>)  &amp; (<span class="number">0x7f</span>) ;</span><br><span class="line">    <span class="type">uint8_t</span> payload1 =  *(res-&gt;dst + <span class="number">4</span>);</span><br><span class="line">    <span class="type">uint8_t</span> payload2 = *(res-&gt;dst + <span class="number">5</span>);</span><br><span class="line">    <span class="type">uint8_t</span> frame_offset;</span><br><span class="line">    <span class="type">uint16_t</span> len;</span><br><span class="line">    <span class="type">uint8_t</span> encry_type;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* since put 2 bytes one time, so it has to mulitplied by 2 */</span></span><br><span class="line">    index = index &lt;&lt; <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">if</span> (<span class="number">1</span> == get_all) &#123;</span><br><span class="line">        <span class="keyword">return</span> FAILURE_RETURN;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (index &gt; MCAST_MAX_LEN) &#123;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> VERBOSE_MCAST_DEBUG</span></span><br><span class="line">        awss_debug(<span class="string">&quot;error index\n&quot;</span>);</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">        <span class="keyword">return</span> FAILURE_RETURN;</span><br><span class="line">    &#125;</span><br><span class="line">    len = res-&gt;u.br.data_len;</span><br><span class="line">    encry_type = res-&gt;u.br.encry_type;</span><br><span class="line"></span><br><span class="line">    frame_offset = zconfig_fixed_offset[encry_type][<span class="number">0</span>];</span><br><span class="line"></span><br><span class="line">    len -= frame_offset;</span><br><span class="line">    <span class="keyword">if</span> (len != <span class="number">1</span>) &#123;</span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> VERBOSE_MCAST_DEBUG</span></span><br><span class="line">        awss_debug(<span class="string">&quot;error len, len is %d\n&quot;</span>, len);</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">        <span class="keyword">return</span> FAILURE_RETURN;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/* Filter out interference */</span></span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">         * 1) src not equal, bssid equal, interference</span></span><br><span class="line"><span class="comment">         * 2) src not equal, bssid not equal, interference</span></span><br><span class="line"><span class="comment">         * 3) src equal, bssid equal, good, go on</span></span><br><span class="line"><span class="comment">         * 4) src equal, bssid not equal</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (!<span class="built_in">memcmp</span>(mcast_src_mac, zero_mac, ETH_ALEN)) &#123;</span><br><span class="line">        <span class="built_in">memcpy</span>(mcast_bssid_mac, res-&gt;bssid, ETH_ALEN);</span><br><span class="line">        <span class="built_in">memcpy</span>(mcast_src_mac, res-&gt;src, ETH_ALEN);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="comment">/* case 1, 2 */</span></span><br><span class="line">        <span class="keyword">if</span>(<span class="built_in">memcmp</span>(mcast_src_mac, res-&gt;src, ETH_ALEN)) &#123;</span><br><span class="line">            <span class="keyword">return</span> FAILURE_RETURN;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* lock channel */</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0</span> == find_channel_from_aplist) &#123;</span><br><span class="line">        lock_mcast_channel(res, encry_type);</span><br><span class="line">    &#125;</span><br><span class="line">    processed_packet++;</span><br><span class="line"></span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: index is %d, %d, %d, %d\n&quot;</span>, index, payload1, payload2, len);</span><br><span class="line"></span><br><span class="line">    mcast_smartconfig_data.data[index] = payload1;</span><br><span class="line">    receive_record[index] = <span class="number">1</span>;</span><br><span class="line">    index++;</span><br><span class="line">    mcast_smartconfig_data.data[index] = payload2;</span><br><span class="line">    receive_record[index] = <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0</span> != receive_record[<span class="number">0</span>]) &#123;</span><br><span class="line">        <span class="type">int</span> remain = <span class="number">-1</span>;</span><br><span class="line">        mcast_smartconfig_data.tlen = mcast_smartconfig_data.data[<span class="number">0</span>];</span><br><span class="line">        remain = mcast_receive_done();</span><br><span class="line">        <span class="keyword">if</span> (<span class="number">0</span> == remain) &#123;</span><br><span class="line">            get_all = <span class="number">1</span>;</span><br><span class="line">            parse_result();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> PKG_MCAST_FRAME;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-3-parse-result"><a href="#3-3-parse-result" class="headerlink" title="3.3 parse_result()"></a><font size=3>3.3 parse_result()</font></h3><p>解析SSID和密码等相关数据的函数：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">parse_result</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> offset = <span class="number">0</span>;</span><br><span class="line">    <span class="type">int</span> ret, valid_bssid;</span><br><span class="line">    <span class="type">uint8_t</span> BIT0_passwd = <span class="number">0</span>;</span><br><span class="line">    <span class="type">uint8_t</span> BIT1_ssid = <span class="number">0</span>;</span><br><span class="line">    <span class="type">uint8_t</span> BIT2_token = <span class="number">0</span>;</span><br><span class="line">    <span class="type">uint8_t</span> BIT6_7_version = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: tlen is %d\n&quot;</span>, mcast_smartconfig_data.tlen);</span><br><span class="line">    mcast_smartconfig_data.flag = mcast_smartconfig_data.data[<span class="number">1</span>];</span><br><span class="line">    offset = <span class="number">2</span>;</span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: flag is %d\n&quot;</span>, mcast_smartconfig_data.flag);</span><br><span class="line"></span><br><span class="line">    BIT0_passwd = <span class="number">0x1</span> &amp; mcast_smartconfig_data.flag;</span><br><span class="line">    BIT1_ssid = <span class="number">0x1</span> &amp; (mcast_smartconfig_data.flag &gt;&gt; <span class="number">1</span>);</span><br><span class="line">    BIT2_token = <span class="number">0x1</span> &amp; (mcast_smartconfig_data.flag &gt;&gt; <span class="number">2</span>);</span><br><span class="line">    BIT6_7_version = <span class="number">0x3</span> &amp; (mcast_smartconfig_data.flag &gt;&gt; <span class="number">6</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0x3</span> != BIT6_7_version) &#123;</span><br><span class="line">        awss_err(<span class="string">&quot;error version&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">1</span> == BIT0_passwd) &#123;</span><br><span class="line">        mcast_smartconfig_data.passwd_len = mcast_smartconfig_data.data[<span class="number">2</span>];</span><br><span class="line">        awss_debug(<span class="string">&quot;mcast: passwd_len is %d\n&quot;</span>, mcast_smartconfig_data.passwd_len);</span><br><span class="line">        mcast_smartconfig_data.passwd = &amp;(mcast_smartconfig_data.data[<span class="number">3</span>]);</span><br><span class="line">        offset = <span class="number">3</span> + mcast_smartconfig_data.passwd_len;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">1</span> == BIT2_token) &#123;</span><br><span class="line">        mcast_smartconfig_data.token_len = mcast_smartconfig_data.data[offset];</span><br><span class="line">        awss_debug(<span class="string">&quot;mcast: token_len is %d\n&quot;</span>, mcast_smartconfig_data.token_len);</span><br><span class="line">        offset++;</span><br><span class="line">        mcast_smartconfig_data.token = &amp;(mcast_smartconfig_data.data[offset]);</span><br><span class="line">        awss_debug(<span class="string">&quot;mcast: token is %.*s\n&quot;</span>, mcast_smartconfig_data.token_len, mcast_smartconfig_data.token);</span><br><span class="line">        offset += mcast_smartconfig_data.token_len;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (<span class="number">1</span> == BIT1_ssid) &#123;</span><br><span class="line">        mcast_smartconfig_data.ssid_len = mcast_smartconfig_data.data[offset];</span><br><span class="line">        awss_debug(<span class="string">&quot;mcast: ssid_len is %d\n&quot;</span>, mcast_smartconfig_data.ssid_len);</span><br><span class="line">        offset++;</span><br><span class="line">        mcast_smartconfig_data.ssid = &amp;(mcast_smartconfig_data.data[offset]);</span><br><span class="line">        awss_debug(<span class="string">&quot;mcast: ssid is %.*s\n&quot;</span>, mcast_smartconfig_data.ssid_len, mcast_smartconfig_data.ssid);</span><br><span class="line">        offset += mcast_smartconfig_data.ssid_len;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    mcast_smartconfig_data.bssid_type_len = mcast_smartconfig_data.data[offset];</span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: bssid_type_len is %d\n&quot;</span>, mcast_smartconfig_data.bssid_type_len);</span><br><span class="line">    offset++;</span><br><span class="line">    mcast_smartconfig_data.bssid = &amp;(mcast_smartconfig_data.data[offset]);</span><br><span class="line">    <span class="comment">/* get bssid len from last 5 bits from bssid_type_len */</span></span><br><span class="line">    offset += mcast_smartconfig_data.bssid_type_len &amp; <span class="number">0x1f</span>;</span><br><span class="line">    mcast_smartconfig_data.checksum = mcast_smartconfig_data.data[offset];</span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: checksum is %d\n&quot;</span>, mcast_smartconfig_data.checksum);</span><br><span class="line">    awss_debug(<span class="string">&quot;mcast: total processed %d packagets \n&quot;</span>, processed_packet);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* set zc_bssid*/</span></span><br><span class="line">    valid_bssid = set_zc_bssid();</span><br><span class="line">    <span class="comment">/* set zc_ssid */</span></span><br><span class="line">    set_zc_ssid(valid_bssid);</span><br><span class="line">    ret = verify_checksum();</span><br><span class="line">    <span class="keyword">if</span> (SUCCESS_RETURN != ret) &#123;</span><br><span class="line">        awss_err(<span class="string">&quot;mcast: checksum mismatch\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    ret = decode_passwd();</span><br><span class="line">    gen16ByteToken();</span><br><span class="line">    reset_mcast_data();</span><br><span class="line">    <span class="keyword">if</span> (SUCCESS_RETURN != ret) &#123;</span><br><span class="line">        awss_err(<span class="string">&quot;mcast: passwd error\n&quot;</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/* <span class="doctag">TODO:</span> check channel info*/</span></span><br><span class="line">    zconfig_set_state(STATE_RCV_DONE, <span class="number">0</span>, mcast_locked_channel);</span><br><span class="line">    <span class="keyword">return</span> SUCCESS_RETURN;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-4-密码解析"><a href="#3-4-密码解析" class="headerlink" title="3.4 密码解析"></a><font size=3>3.4 密码解析</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">decode_passwd</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> passwd_len = <span class="number">0</span>;</span><br><span class="line">    <span class="comment">/* CAN&#x27;T use snawss_debug here, because of SPACE char */</span></span><br><span class="line">    passwd_len = mcast_smartconfig_data.passwd_len;</span><br><span class="line">    <span class="built_in">memset</span>(zc_passwd, <span class="number">0</span>, ZC_MAX_PASSWD_LEN);</span><br><span class="line">    aes_decrypt_string((<span class="type">char</span> *)(mcast_smartconfig_data.passwd), (<span class="type">char</span> *)zc_passwd,</span><br><span class="line">                       passwd_len,</span><br><span class="line">                       <span class="number">1</span>, awss_get_encrypt_type(), <span class="number">0</span>, <span class="literal">NULL</span>);</span><br><span class="line">    <span class="keyword">if</span> (is_utf8((<span class="type">const</span> <span class="type">char</span> *)zc_passwd, passwd_len) == <span class="number">0</span>) &#123;</span><br><span class="line">        awss_trace(<span class="string">&quot;passwd err\r\n&quot;</span>);</span><br><span class="line">        awss_event_post(IOTX_AWSS_PASSWD_ERR);</span><br><span class="line">        AWSS_UPDATE_STATIS(AWSS_STATIS_SM_IDX, AWSS_STATIS_TYPE_PASSWD_ERR);</span><br><span class="line">        <span class="keyword">return</span> FAILURE_RETURN;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> SUCCESS_RETURN;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/23891e91.html">LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年12月22日 - 22:28</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/23891e91.html" title="LV02-01-天猫精灵IOT-07-SmartConfig-05-多播配网代码分析">https://sumumm.github.io/post/23891e91.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/" rel="tag"><i class="fa fa-tag"></i> LV21-天猫精灵IOT</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/bb7e01c5.html" rel="prev" title="LV03-01-蓝牙-01-蓝牙发展史">
                  <i class="fa fa-angle-left"></i> LV03-01-蓝牙-01-蓝牙发展史
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/9d665328.html" rel="next" title="LV02-01-天猫精灵IOT-07-SmartConfig-04-广播配网代码分析">
                  LV02-01-天猫精灵IOT-07-SmartConfig-04-广播配网代码分析 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
